import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { FairylandPropItem } from "./FairylandPropItem";
import { Language } from "../../../../extend/language/Language";
import { ResFileConst } from "../../resource/ResFileConst";
import { ShopConfig } from "../../resource/ShopConfig";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { ItemData } from "../../resource/info/ItemData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GuideArrowManager } from "../../manager/GuideArrowManager";
import { SystemSetter } from "../system/SystemSetter";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class CopyFairylandPropPanel
    
    export  class CopyFairylandPropPanel extends View
    {
        constructor()
        {
            super();
            this._propItemArr = [];
            layer = LayerManager.uiLayer;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc3=null;
            var loc6=null;
            var loc7=0;
            var loc1=ObjCreate.createBg(0, 0, 150, 110, this, ImagesConst.ToolTipBg);
            var loc2=ObjCreate.createBg(5, 5, 140, 100, this, ImagesConst.WindowCenterB);
            loc3 = this.getConfigProp();
            var loc4=10;
            var loc5=10;
            loc7 = 0;
            while (loc7 < 3) 
            {
                (loc6 = new FairylandPropItem()).x = loc4;
                loc6.y = loc5;
                loc6.update(loc3[loc7]);
                addChild(loc6);
                loc4 = loc4 + 45;
                this._propItemArr.push(loc6);
                ++loc7;
            }
            this._propBuyCb = ObjCreate.createCheckBox(Language.getString(60102), 15, 80, 150, 20, this);
            this._propBuyCb.addEventListener(flash.events.Event.CHANGE, this.onPropBuyCbChangeHandler);
            var loc8;
            (loc8 = ObjCreate.createGLoadedButton(ResFileConst.MagicTowerLeaveBtn, 160, 30, 50, 50, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onLeaveCopyBtnClickHandler);
            return;
        }

        /* internal  */getConfigProp(): Array<any>
        {
            var loc1=null;
            var loc4=null;
            var loc2=[];
            var loc3=ShopConfig.instance.getShopItemInfoArrayByType(ECategory._ECategoryProp, EProp._EPropLottery, -1, false);
            var loc5=0;
            while (loc5 < loc3.length) 
            {
                if ((loc4 = loc3[loc5]).unit == EPrictUnit._EPriceUnitGold) 
                {
                    loc1 = new ItemData(loc4.itemInfo.item.code);
                    loc2.push(loc1);
                }
                ++loc5;
            }
            return loc2;
        }

        /* internal  */onLeaveCopyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyQuitCopy, null));
            return;
        }

        /* internal  */onPropBuyCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._propItemArr;
            for(loc1 of loc3) 
            {
                loc1.isDirect = this._propBuyCb.selected;
            }
            return;
        }

        public showGuideArrow(): void
        {
            var loc1=GuideArrowManager.getGuideArrow(GuideArrowManager.Dir_R, null, 0);
            loc1.x = 0;
            loc1.y = 60;
            addChild(loc1);
            return;
        }

        public removeGuideArrow(): void
        {
            if (GuideArrowManager.guideArrow.parent == this) 
            {
                GuideArrowManager.hideGuideArrow();
                SystemSetter.localSetter.isGuideUse = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Sys_SaveInfoNotShowInWindow));
            }
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (GuideArrowManager.guideArrow.parent == this) 
            {
                GuideArrowManager.hideGuideArrow();
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updatePropNum();
            return;
        }

        public updatePropNum(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._propItemArr;
            for(loc1 of loc3) 
            {
                loc1.updatePropNum();
            }
            return;
        }

        /* internal */ /* var */_propBuyCb: GCheckBox;

        /* internal */ /* var */_propItemArr: Array<any>;
    }
